import random
from datetime import datetime, timedelta

from faker import Faker

from api.base_api import BasePrimeSpApi

fake = Faker(locale='zh_CN')


class Prime_InvestFixed_Add_FixedInfo(BasePrimeSpApi):
    """
    创建项目
    """
    testname = ''

    def __init__(self, name, currency, LimitMax, LimitMin, returnTime_days, investEndTime_days):
        super().__init__()
        now_dt = datetime.now()
        returnTime = now_dt + timedelta(days=returnTime_days)
        returnTime = int(returnTime.timestamp() * 1000)

        investEndTime = now_dt + timedelta(days=investEndTime_days)
        investEndTime = int(investEndTime.timestamp() * 1000)
        self.url = f'{self.host}/api/prime/investFixed/addFixedInfo'
        self.method = 'post'
        self.json = {
            "name": f"{name}{fake.date_time_between_dates()}-{currency}-0817-{random.randint(1, 10)}D",
            "sortNum": 989,
            "investCurrency": currency,
            "cancelOrderFlag": 2,
            "labelZhTwJsons": [{
                "labelValue": "中文标签11111",
                "labelFontColor": "#F75E1C"
            }],
            "labelEnJsons": [{
                "labelValue": "英文标签11111",
                "labelFontColor": "#C418DE"
            }],
            "profitCalculationType": 1,
            "annualizedProfitRate": "0.11",
            "annualizedProfitRatePersonal": "0.01",
            "annualizedProfitRatePlatform": "0.1",
            "investEndTime": investEndTime,
            "returnTime": returnTime,
            "lockInterval": 2,
            "raiseLimitMax": LimitMax,
            "raiseLimitMin": LimitMin,
            "productTypeSubId": 3
        }
        Prime_InvestFixed_Add_FixedInfo.testname = self.json['name']


class PrimeInvestFixedGetFixedInfoList(BasePrimeSpApi):
    """
    查询服务商项目列表
    """

    def __init__(self):
        super().__init__()

        self.url = f'{self.host}/api/prime/investFixed/getFixedInfoList'
        self.method = 'get'
        self.params = {
            "tab": 1,
            "id": '',
            "name": '',
            "nameLike": 'false',
            "showName": '',
            "showNameLike": 'false',
            "investCurrency": '',
            "status": '',
            "auditStatus": '',
            "page": '1',
            "size": '20'
        }


class AuditSubmit(BasePrimeSpApi):
    """
    项目审核
    """

    def __init__(self, orderid):
        super().__init__()

        self.url = f'{self.host}/api/prime/audit/submit/{orderid}'
        self.method = 'post'


if __name__ == '__main__':
    print(random.randint(1, 10))
    print(fake.date_time_between_dates())
